package com.nagarro.inventory;

/**
 * Class to represent an item in the market.
 * An item has four properties: name, price, quantity  and type
 * @author uditverma
 *
 */
public abstract class Item {
	
	
	private static final float TAX_PERCENTAGE = .125f;
	
	/* name of the item*/
	private String name;
	
	/*price of the item*/
	private double price;
	
	/*total tax applicable on the object */
	private double tax;
	
	/**
	 * function to return the final cost of the item based on tax, price and quantity.
	 * @param quantity quantity of the item purchased
	 * @return final cost of the item payable by the user
	 */
	public abstract double getTotal(final int quantity);
	
	/**
	 * calculate the tax
	 * @param cost cost of the item
	 * @return tax to be added
	 */
	protected double getTax(final double cost) {
		return cost * TAX_PERCENTAGE;
	}
	
	/**
	 * calculate the cost as the product of quantity and cost of one item
	 * @param quantity number of items to be purchased
	 * @return cost of the item
	 */
	protected double getCost(int quantity) {
		return this.getPrice() * quantity;
	}
	
	public String getName() {
		return name;
	}

	public void setName(final String name) {
		this.name = name;
	}

	public double getPrice() {
		return price;
	}

	public void setPrice(final double price) {
		if(price >= 0) {
			this.price = price;
		} else {
			this.price = 0;
		}
	}

	public double getTax() {
		return tax;
	}

	protected void setTax(final double tax) {
		this.tax = tax;
	}	
}
